package com.information.service.impl;

import com.common.constant.enums.CommonStatus;
import com.common.constant.strings.ErrorMsg;
import com.common.constant.strings.SuccessMsg;
import com.common.entity.information.TbInformation;
import com.common.response.CommonResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.information.mapper.InformationMapper;
import com.information.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationServiceImpl implements InformationService {

    @Autowired
    private InformationMapper informationMapper;

    @Override
    public PageInfo<TbInformation> findAll(Integer page,Integer size,TbInformation information) {
        PageHelper.startPage(page,size);
        List<TbInformation> list = informationMapper.findAll(information);
        return new PageInfo<>(list);
    }

    @Override
    public CommonResponse updateStatus(Long id,Integer status) {
        try {
            informationMapper.updateStatus(id,status);
            return new CommonResponse(CommonStatus.SUCCESS.getCode(), SuccessMsg.SUCCESS_CODE_200);
        }catch (Exception e){
            e.printStackTrace();
            return new CommonResponse(CommonStatus.ERROR.getCode(), ErrorMsg.ERROR_OPERATION_404);
        }
    }
}
